
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="/static/css/public.css"/>
    <link rel="stylesheet" href="/static/css/style.css"/>
    <script type="text/javascript" src="/static/js/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            //获取所有供应商信息
            $.get("/sys/provider/queryAll",function (result) {
                $("select[name='providerId']").append("<option value='-1'>--请选择--</option>");
                $.each(result, function (index, d) {
                    $("select[name='providerId']").append("<option value='"+d.id+"'>"+d.proName+"</option>");
                });
                var providerId = $("#providerId").val();
                if(providerId!=''){
                    $("select[name='providerId']").val(providerId);
                }
            });
            //是否已付款
            var isPayment = $("#isPayment").val();
            if(isPayment!=''){
                $("select[name='isPayment']").val(isPayment);
            }

            //删除按钮单击事件
            $("a[name='delete']").click(function () {
                //获取id
                var id = $(this).attr("billId");
                if(confirm("确定要删除此订单吗？")){
                    $.get("/sys/bill/delete","id="+id,function (result) {
                        if (result == 'success'){
                            alert("订单删除成功！");
                            //删除成功后刷新当前页
                            location.href=location.href
                        }else {
                            alert("删除订单失败，请稍后再试！")
                        }
                    });
                }
            })
        })
    </script>
</head>
<body>
<section class="publicMian ">
    <div class="right" style="width: 100%">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>账单管理页面</span>
        </div>
        <div class="search">
            <form id="searchForm">
                <span>商品名称：</span>
                <input type="text" name="productName" value="${bill.productName}" placeholder="请输入商品的名称"/>

                <span>供应商：</span>
                <input type="hidden" id="providerId" value="${bill.providerId}">
                <select name="providerId" >
                </select>

                <span>是否付款：</span>
                <select name="isPayment">
                    <option value="-1">--请选择--</option>
                    <option value="2">已付款</option>
                    <option value="1">未付款</option>
                </select>
                <input type="hidden" id="isPayment" value="${bill.isPayment}">
                <input type="button" value="查询" id="searchButton"/>
                <a href="/sys/bill/toSave">添加订单</a>
            </form>
        </div>
        <!--账单表格 样式和供应商公用-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">账单编码</th>
                <th width="20%">商品名称</th>
                <th width="10%">供应商</th>
                <th width="10%">账单金额</th>
                <th width="10%">是否付款</th>
                <th width="10%">创建时间</th>
                <th width="30%">操作</th>
            </tr>
            <c:forEach items="${pageInfo.list}" var="bill">
            <tr>
                <td>${bill.billCode}</td>
                <td>${bill.productName}</td>
                <td>${bill.provider.proName}</td>
                <td>${bill.totalPrice}</td>
                <td>
                    <c:if test="${bill.isPayment==1}">未支付</c:if>
                    <c:if test="${bill.isPayment==2}">已支付</c:if>
                </td>
                <td>
                        <fmt:formatDate value="${bill.creationDate}" pattern="yyyy-MM-dd"/>

                </td>

                <td>
                    <a href="/sys/bill/toDetail?id=${bill.id}"><img src="/static/img/read.png" alt="查看" title="查看"/></a>
                    <a href="providerUpdate.html"><img src="/static/img/xiugai.png" alt="修改" title="修改"/></a>
                    <a name="delete" billId="${bill.id}"><img src="/static/img/schu.png" alt="删除" title="删除"/></a>
                </td>
            </tr>
            </c:forEach>
        </table>
        <!--引用分页页面-->
        <jsp:include page="page.jsp"></jsp:include>
    </div>
</section>

</body>
</html>
